package org.yourscrum.web;

import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.support.SessionStatus;
import org.yourscrum.service.ThemeMapper;
import org.yourscrum.service.ThemeService;
import org.yourscrum.web.ThemeVO;

/**
 * @author Jettro Coenradie
 */
public class EditThemeController {
    private ThemeService themeService;

    public EditThemeController(ThemeService themeService) {
        this.themeService = themeService;
    }

    public String setupForm(long themeId, ModelMap model) {
        ThemeVO theme = ThemeMapper.map(themeService.obtainThemeById(themeId));

        model.addAttribute("theme", theme);
        return "themeForm";
    }

    public String processSubmit(ThemeVO theme, BindingResult result, SessionStatus sessionStatus) {
        this.themeService.storeTheme(theme);
        sessionStatus.setComplete();
        return "redirect:themes.html";
    }
}
